package com.gene.service.impl;

import com.gene.mapper.TbContentCategoryMapper;
import com.gene.pojo.TbContentCategory;
import com.gene.pojo.TbContentCategoryExample;
import com.gene.service.ITbContentCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class TbContentCategoryServiceImpl implements ITbContentCategoryService{

    @Autowired
    private TbContentCategoryMapper tbContentCategoryMapper;
    /**
     * 查询分类，父类目ID=0时，代表的是一级的类目
     */
    public List<TbContentCategory> query(Integer id) {
        TbContentCategoryExample example=new TbContentCategoryExample();
        TbContentCategoryExample.Criteria criteria=example.createCriteria();
        criteria.andParentIdEqualTo((long)id);
        criteria.andStatusEqualTo(1);
        return tbContentCategoryMapper.selectByExample(example);
    }

    /**
     * 根据分类ID修改
     */
    public Boolean update(TbContentCategory tbContentCategory){
        tbContentCategory.setUpdated(new Date());
        return tbContentCategoryMapper.updateByPrimaryKeySelective(tbContentCategory)==1?true:false;
    }
    /**
     * 添加分类
     */
    public boolean save(TbContentCategory tbContentCategory) {
        tbContentCategory.setCreated(new Date());
        return tbContentCategoryMapper.insert(tbContentCategory)==1?true:false;
    }
    /**
     * 根据ID和status显示或隐藏分类
     */
    public boolean del(Integer id,Integer status) {
        TbContentCategory tbContent=new TbContentCategory();
        tbContent.setStatus(status);
        TbContentCategoryExample example=new TbContentCategoryExample();
        TbContentCategoryExample.Criteria criteria=example.createCriteria();
        criteria.andIdEqualTo((long)id);
         return  tbContentCategoryMapper.updateByExampleSelective(tbContent,example)==1?true:false;
    }
}
